package com.cunfang.util;

import java.util.HashMap;
import java.util.Map;


/**
 * config.properties配置文件读取
 * 
 * @author RXJ
 *
 */
public final class ConfigUtil {

	/**
	 * 当前对象实例
	 */
	private static ConfigUtil config ;
	
	/**
	 * 保存全局属性值
	 */
	private static Map<String, String> map = new HashMap<String, String>();
	
	public static PropertiesLoader loader =new PropertiesLoader("config.properties");
	
	
	/**读取配置参数
	 * @param key
	 * @return
	 */
	public static String getProperties(String key){
		String value = map.get(key);
		if(value==null){
			value = loader.getProperty(key);
			ConfigUtil.map.put(key, value != null ? value : null);
		}
		return value;
	}

	/**
	 * 获取配置
	 * @see ${fns:getConfig('adminPath')}
	 */
	public static String getConfig(String key) {
		String value = map.get(key);
		if (value == null){
			value = loader.getProperty(key);
			map.put(key, value != null ? value : "");
		}
		return value;
	}
	
	public ConfigUtil(){
		if(config==null){
			synchronized(ConfigUtil.class){
				config = new ConfigUtil();
			}
		}
	}
	
}
